//
//  FilterCriteriaVideoListViewController.swift
//  月升
//
//  Created by 拉利法 on 2024/7/11.
//  美妆推荐视频列表

import UIKit

class FilterCriteriaVideoListViewController: QIBaseViewController {

    
    var previewImg = UIImage()
    /// 原图在本地服务器地址
    var originalImgUrl = ""
    /// 原图地址
    var raw_file_path = ""
    /// 时间名称
    var event_name = ""
    /// 五官检测结果
    var wuGuanModel = QIFiveSensesResultModel()
    /// 美妆视频推荐列表
    var recommenListModelArr = [QIBeautyRecommenListModel]()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "美妆推荐"

        addUI()
    }
    

  
    private func addUI() {
        showGradientColor()
        
        view.addSubview(tableView)
    }
    
    
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.frame = CGRect(x: 0, y: NAV_HEIGHT, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - NAV_HEIGHT)
        tableView.backgroundColor = .clear
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        if #available(iOS 15.0, *) {
            tableView.sectionHeaderTopPadding = 0
        } else {}
        return tableView
    }()

}


extension FilterCriteriaVideoListViewController: UITableViewDataSource, UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return recommenListModelArr.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        110
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = FilterCriteriaVideoListViewCell()
        cell.selectionStyle = .none
        cell.model = recommenListModelArr[indexPath.row]
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let ctl = FilterCriteriaVideoInfoViewController()
        ctl.previewImg = previewImg
        ctl.originalImg = previewImg
        ctl.model = recommenListModelArr[indexPath.row]
        ctl.event_name = event_name
        ctl.wuGuanModel = wuGuanModel
        ctl.raw_file_path = raw_file_path
        ctl.originalImgUrl = originalImgUrl
        navigationController?.pushViewController(ctl, animated: true)
    }
    
}



class FilterCriteriaVideoListViewCell: UITableViewCell {
    
    private let bgView = UIView()
    private var titleL = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        addUI()
    }
    func addUI() {
        
        bgView.frame = CGRect(x: 15, y: 5, width: SCREEN_WIDTH - 30, height: 100)
        bgView.backgroundColor = UIColor(white: 1, alpha: 0.5)
        bgView.addRoundedCorners(withRadius: 10)
        self.contentView.addSubview(bgView)
        
        let titleL1 = UILabel().then({
            $0.frame = CGRect(x: 12, y: 12, width: 80, height: 22)
            $0.text = "推荐风格:"
            $0.textColor = Color333333
            $0.font = FONT(ofSize: 16)
        })
        bgView.addSubview(titleL1)
        
        titleL = UILabel().then({
            $0.frame = CGRect(x: titleL1.right, y: 12, width: 200, height: 22)
            $0.text = ""
            $0.textColor = MainColor
            $0.font = FONT(ofSize: 16)
        })
        bgView.addSubview(titleL)
//        
//        let titleArr = ["社交妆容", "时长中等", "难度容易"]
//        var x = 12.0
//        for (index, titleStr) in titleArr.enumerated() {
//            let itemW = titleStr.getLabelWidth(font: FONT(ofSize: 14), height: 20) + 20
//            let tagL = UILabel().then({
//                $0.frame = CGRect(x: x, y: titleL.bottom + 20, width: itemW, height: 28)
//                $0.text = titleStr
//                $0.textAlignment = .center
//                $0.textColor = MainColor
//                $0.font = FONT(ofSize: 14)
//                $0.addRoundedCorners(withRadius: 14)
//                $0.addBorder(withWidth: 1, borderColor: MainColor)
//            })
//            bgView.addSubview(tagL)
//            x = tagL.right + 10
//        }
        
    }
    
    var model = QIBeautyRecommenListModel() {
        didSet {
            titleL.text = model.title
//            titleL.text = model.makeup_type.joined(separator: "/")
            let titleArr = [model.vModel.application, "\(model.vModel.duration)秒", "难度\(model.vModel.difficulty)"]
            var x = 12.0
            for (_, titleStr) in titleArr.enumerated() {
                let itemW = titleStr.getLabelWidth(font: FONT(ofSize: 14), height: 20) + 20
                let tagL = UILabel().then({
                    $0.frame = CGRect(x: x, y: titleL.bottom + 20, width: itemW, height: 28)
                    $0.text = titleStr
                    $0.textAlignment = .center
                    $0.textColor = MainColor
                    $0.font = FONT(ofSize: 14)
                    $0.addRoundedCorners(withRadius: 14)
                    $0.addBorder(withWidth: 1, borderColor: MainColor)
                })
                bgView.addSubview(tagL)
                x = tagL.right + 10
            }
        }
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}

